package com.mljr.example.adapter.tab1;

import android.content.Context;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ctakit.sdk.app.widget.image.CircleImageView;
import com.ctakit.sdk.view.ViewInjector;
import com.ctakit.sdk.view.annotation.ViewInject;
import com.mljr.example.R;
import com.mljr.example.adapter.BaseListAdapter;
import com.mljr.example.bean.tab1.ChannelIcon;
import com.mljr.example.ui.icon.Icons;

import java.util.List;


/**
 * Created by andyhome on 16/4/20.
 */
public class HeaderChannelAdapter extends BaseListAdapter<ChannelIcon> {

    private  Typeface font;
    public HeaderChannelAdapter(Context context, List<ChannelIcon> list) {
        super(context, list);
        font = Typeface.createFromAsset(context.getAssets(), "m-fonts.ttf");
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.tab1_item_channel, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ChannelIcon entity = getItem(position);
        holder.ivImage.setTypeface(font);
        Icons.setHomeChannelIcon(entity.getIconClassId(),holder.ivImage,holder.voucherBg);




        holder.tvTitle.setText(entity.getName());
        //ImgConfig.loadImg(AppUtils.getContext(),entity.getImageUrl(), holder.ivImage);
        if (TextUtils.isEmpty(entity.getIconLabel())) {
            holder.tvTips.setVisibility(View.INVISIBLE);
        } else {
            holder.tvTips.setVisibility(View.VISIBLE);
            holder.tvTips.setText(entity.getIconLabel());
        }

        return convertView;
    }

    static class ViewHolder {
        @ViewInject(R.id.iv_image)
        TextView ivImage;
        @ViewInject(R.id.voucher_bg)
        CircleImageView voucherBg;
        @ViewInject(R.id.tv_title)
        TextView tvTitle;
        @ViewInject(R.id.tv_tips)
        TextView tvTips;

        ViewHolder(View view) {
            ViewInjector.inject(this, view);
        }
    }
}
